/*
 * @Author: Cao Shixin
 * @Date: 2021-03-22 10:34:06
 * @LastEditors: Cao Shixin
 * @LastEditTime: 2021-05-11 14:02:20
 * @Description: 
 */
import 'package:flutter/foundation.dart';

import '../logger_util.dart';

/// 打印工具类，添加时间，文字超长会换行打印
/// deprecated. Please use logger
@Deprecated('废弃，请使用LogUtil类方法 或者LogObject对象模式')
class PrintUtil {
  /// 控制打印 在Release环境默认false
  static bool enableLog = kDebugMode;

  /// 通用打印方法 [enableLog]为true会打印
  static void print(dynamic message, {int maxLength = 800}) {
    if (message != null) {
      var content = message.toString();
      if (kDebugMode) {
        if (content == '') {
          LogUtil.logD(DateTime.now().toIso8601String());
          return;
        }
        while (content.length > maxLength) {
          LogUtil.logD(
              '${DateTime.now().toIso8601String()} ${content.substring(0, maxLength)}');
          content = content.substring(maxLength, content.length);
        }
        if (content != '') {
          LogUtil.logD('${DateTime.now().toIso8601String()} $content');
        }
      } else {
        LogUtil.logI(content);
      }
    }
  }

  /// 打印分隔线，[text]会居中打印
  static void printDivider(
      {int length = 160,
      String text = '',
      String? by,
      String? prefixBy,
      String? suffixBy,
      int minDividerCount = 10}) {
    PrintUtil.print('');
    if (by != null) {
      prefixBy = by;
      suffixBy = by;
    }
    if (text.length > length) {
      PrintUtil.print(
        '${prefixBy! * minDividerCount}$text${suffixBy! * minDividerCount}',
      );
    } else {
      final prefix = prefixBy! * ((length - text.length) / 2).floor();
      final suffix = suffixBy! * (length - prefix.length - text.length);
      PrintUtil.print(
        '$prefix$text$suffix',
      );
    }
    PrintUtil.print('');
  }
}
